//
// Copyright (c) 2009 All Right Reserved
//
// stoub@microsoft.com
// 2009-01-01
// Contains ...
// Class to represent an entire track in a MIDI file.
using System.Diagnostics.Contracts;
using System.Linq;
using JetBrains.Annotations;
namespace LargoCommon.Midi
{
/// Represents a single MIDI track in a MIDI file.
public sealed class MidiTrackMetaInfo {
/// Collection of MIDI event added to this track.
private readonly MidiEventCollection events;
///
/// Initializes a new instance of the class.
///
/// The given midi track.
public MidiTrackMetaInfo(IMidiTrack givenMidiTrack) {
Contract.Requires(givenMidiTrack != null);
this.events = givenMidiTrack.Events;
this.ReadMetaProperties();
}
///
/// Initializes a new instance of the class.
///
[UsedImplicitly]
public MidiTrackMetaInfo() {
}
#region Public Meta Properties
///
/// Gets MetaText.
///
/// Property description.
public string MetaText { get; private set; }
///
/// Gets MetaSequenceTrackName.
///
/// Property description.
public string MetaSequenceTrackName { get; private set; }
///
/// Gets MetaInstrument.
/// Property description.
///
/// Property description.
public string MetaInstrument { get; private set; }
///
/// Gets the name of the guess.
///
///
/// The name of the guess.
///
public string GuessName => ((this.MetaSequenceTrackName ?? this.MetaText) ?? this.MetaInstrument) ?? string.Empty;
#endregion
#region Support
/// Read MetaProperties.
[ContractVerification(false)]
private void ReadMetaProperties()
{
foreach (var ev in this.events.Where(ev => ev != null))
{
this.AssignMetaProperty(ev);
}
}
///
/// Assigns the meta property.
///
/// The midi event.
private void AssignMetaProperty(IMidiEvent midiEvent) { //// cyclomatic complexity 10:13
Contract.Requires(midiEvent != null);
var eventType = midiEvent.EventType;
var metaTextEvent = midiEvent as MetaAbstractText;
var s = metaTextEvent?.Text.Trim();
if (s == null) {
return;
}
switch (eventType) {
case "MetaText":
this.MetaText = s;
break;
case "MetaSequenceTrackName":
this.MetaSequenceTrackName = s;
break;
case "MetaInstrument":
this.MetaInstrument = s;
break;
//// case "LargoBaseMusic.Midi.ProgramChange": this.MelodicInstrumentNumber = ((ProgramChange)ev).Number;
//// break;
//// resharper default: break;
}
}
#endregion
}
}